package com.jzit168.library_arouter

import android.app.Activity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.launcher.ARouter

/**
 *@Desc: 启动路由跳转
 *@Author: Android Developer
 *@Date: 2020/10/15
 *
 **/

/**
 * 普通启动路由跳转
 * @param path 需要跳转的界面的路由路径
 */

fun startARouter(path: String) {
    ARouter.getInstance().build(path).navigation()
}

/**
 * 普通启动路由跳转
 * @param path 需要跳转的界面的路由路径
 * @param bundle 路由跳转携带的bundle参数
 * @see  getARBundle 跳转后如何获取bundle对象的内容
 */
fun startARouter(path: String, bundle: Bundle) {
    ARouter.getInstance().build(path).withBundle("bundle", bundle).navigation()
}

/**
 * 获取Arouter传递的bundle
 * @see startARouter
 */
fun Activity.getARBundle() = intent.getBundleExtra("bundle")

/**
 * 获取Arouter传递的bundle
 * @see startARouter
 */
fun Fragment.getARBundle() = arguments?.getBundle("bundle")

/**
 * 通过路由获取Fragment对象
 * 多用于Activity填充Fragment
 * @param path 需要跳转的View
 */
fun getFragment(path: String) = ARouter.getInstance().build(path).navigation() as Fragment